﻿using Newtonsoft.Json;
using System.Collections;
using UnityEngine;

public static class App
{
    public static void Init()
    {
        InitDefine();
        AfterInitDefine();
    }

    private static void InitDefine()
    {
        InitAppInfoConst();
    }

    private static void InitAppInfoConst()
    {
        if (!Application.isEditor)
        {
            string appInfoText = Resources.Load<TextAsset>("Preset/VersionMgr/AppInfo").text;
            Hashtable appInfo = JsonConvert.DeserializeObject<Hashtable>(appInfoText);

            long channelType = (long)appInfo["ChannelType"];
            AppInfoConst.ChannelType = (ChannelType)channelType;
            AppInfoConst.AppName = (string)appInfo["AppName"];
            AppInfoConst.ChannelName = (string)appInfo["ChannelName"];
            AppInfoConst.IsRelease = (bool)appInfo["IsRelease"];
            AppInfoConst.AppVersion = (string)appInfo["AppVersion"];
            AppInfoConst.BundleVersionCode = (long)appInfo["BundleVersionCode"];
            AppInfoConst.IsRDG = (bool)appInfo["IsRDG"];

            DebugUtil.LogFormat("[App]Channel:{0} AppInfo\n{1}", AppInfoConst.ChannelType, appInfoText);
        }
        else
        {
            AppInfoConst.ChannelType = ChannelType.LocalDebug;
            AppInfoConst.AppName = "开发环境";
            AppInfoConst.ChannelName = "内网测试";
            AppInfoConst.IsRelease = false;
            AppInfoConst.AppVersion = "0.0.0";
            AppInfoConst.BundleVersionCode = 0;
            AppInfoConst.IsRDG = false;
        }
    }

    private static void AfterInitDefine()
    {
        AssemblyConst.AfterInit();
    }

    public static void Quit()
    {
        Application.Quit();
    }
}